<template>
  <div>
    <a-card style="margin-top: 10px" :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :md="6" :sm="8">
              <a-form-item label="发布时间">
                <a-range-picker style="width:100%" show-time @change="changePicker" v-model="rangeTime"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="标题">
                <j-input placeholder="请输入" v-model="queryParam.title"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="发布状态">

                <j-dict-select-tag v-model="queryParam.bpmStatus" placeholder="请选择" dictCode="publish_bpm_status"/>

              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="发布人">
                <select-user-by-dep :multi="false" v-model="queryParam.handlerId"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="签发状态">
                <j-dict-select-tag v-model="queryParam.signStatus" placeholder="请选择" dictCode="publish_sign_status"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="阅读状态">
                <j-dict-select-tag v-model="queryParam.readStatus" placeholder="请选择" dictCode="read_status"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="意见密级">
                <j-dict-select-tag
                  type="list"
                  v-model="queryParam.intensiveType"
                  dictCode="document_intensive_type"
                  placeholder="请选择意见密级"
                />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="resetData" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
              </span>
            </a-col>

          </a-row>
        </a-form>
      </div>

      <a-button style="margin-bottom: 20px;" @click="addOrEditTo('')" type="primary" icon="plus" v-has="'publishCollectAddBtn'">新增</a-button>

      <a-table
        ref="table"
        size="middle"
        bordered
        :scroll="{x: 1500}"
        :components="draggableComponent"
        rowKey="id"
        :columns="columns"
        :customRow="customRow"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">
        <div slot="publishTime" slot-scope="text, record">
          <span style="color:red" v-if="record.readStatus=='0'">*</span>
          {{ formatTime(text) }}
        </div>
        <span slot="action" slot-scope="text, record">
          <a @click="lookTo(record)">查看</a>
          <a-divider type="vertical" v-if="record.bpmStatus!='2'&&record.progress"/>
          <a-dropdown v-if="record.bpmStatus!='2'&&record.progress">
            <a class="ant-dropdown-link">
              更多 <a-icon type="down" />
            </a>
            <a-menu slot="overlay">
              <a-menu-item v-show="record.bpmStatus=='1'&&record.createBy==userInfo().username">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item v-show="record.bpmStatus=='1'">
                <a @click="beginProcess(record)">提交</a>
              </a-menu-item>
              <a-menu-item v-show="record.bpmStatus=='1'">
                <a @click="addOrEditTo(record)">编辑</a>
              </a-menu-item>
              <a-menu-item v-show="record.bpmStatus=='3'&&record.progress">
                <a @click="signPublish(record)">签发</a>
              </a-menu-item>
              <!-- <a-menu-item v-if="userInfo().username=='yangminmin'" v-has="'publishCollectSignProxy'" v-show="record.bpmStatus=='3'&&record.progress!='3'&&record.progress&&record.acceptProxyFlag == 1">
                    <a @click="signProxy(record)">代理签发</a>
                  </a-menu-item> -->
            </a-menu>
          </a-dropdown>

        </span>
      </a-table>

    </a-card>

    <dailogModal ref="opinion" formType="opinion" @ok="loadData"/>
    <opinionSignPublish ref="sign" formType="opinion" @ok="loadData" @close="loadData"/>
    <process-config-modal ref="processConfig" @ok="handleSuccess"></process-config-modal>
  </div>
</template>

<script>
  import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
  import dailogModal from './modules/dailogModal'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import opinionSignPublish from './modules/opinionSignPublish'
  import ProcessConfigModal from '@/views/scy/components/ProcessConfigModal'
  import moment from 'moment'
  import { mapGetters } from 'vuex'
  export default {
    name: 'NoticeAnnounceList',
    mixins: [JeecgBpmListMixin],
    components: {
      dailogModal,
      SelectUserByDep,
      opinionSignPublish,
      ProcessConfigModal
    },
    data () {
      return {
        disableMixinCreated: false,
        rangeTime: null,
        isorter: null,
        columns: [{
              title: '序号',
              width: 60,
              dataIndex: 'id',
              align: 'center',
              customRender: function (t, r, index) {
              return parseInt(index) + 1;
              }
          }, {
              title: '发布时间',
              width: 200,
              scopedSlots: { customRender: 'publishTime' },
              dataIndex: 'publishTime',
              ellipsis: true
          }, {
              title: '截止时间',
              width: 200,
              dataIndex: 'blockingTime',
              ellipsis: true
          }, {
              title: '标题',
              dataIndex: 'title',
              ellipsis: true
          }, {
              title: '发布人',
              width: 100,
              dataIndex: 'handlerId_dictText',
              ellipsis: true
          }, {
              title: '阅读量',
              width: 100,
              dataIndex: 'readCount',
              ellipsis: true,
              customRender: function (text, item) {
                  return `${text}/${item.total}`
              }
          }, {
                title: '发布状态',
                width: 100,
                dataIndex: 'bpmStatus_dictText',
                ellipsis: true
            }, {
                title: '签发状态',
                width: 100,
                dataIndex: 'signStatus_dictText',
                ellipsis: true
            },
            {
                title: '阅读状态',
                width: 100,
                dataIndex: 'readStatus_dictText',
                ellipsis: true
            },
            {
              title: '意见密级',
              width: 100,
              dataIndex: 'intensiveType_dictText',
              ellipsis: true
            },
            {
              title: '操作',
              dataIndex: 'action',
              align: 'center',
              fixed: 'right',
              width: 200,
              scopedSlots: {
                  customRender: 'action',
                  filterDropdown: 'filterDropdown',
                  filterIcon: 'filterIcon'
              } }],
        url: {
          list: '/api/erp/publishCollect/listPage',
          delete: '/api/erp/publishCollect/delete'
        },

        flowCode: 'onl_erp_publish_collect',
        formUrl: '/erp/docManage/modules/opinionForm',
        beanName: 'erpPublishCollectServiceImpl',
        processId: '',
        formUrlMobile: '/pages/synergy/opinionCollectList'
      }
    },
    methods: {
      ...mapGetters(['userInfo']),
      // 双击进入详情
      handleDetail (record) {
        this.lookTo(record)
      },
      formatTime(value) {
        return value ? moment(value).format('YYYY-MM-DD HH:mm') : '-'
      },
      // 重置
      resetData() {
        this.queryParam.publishTime_begin = ''
        this.queryParam.publishTime_end = ''
        this.rangeTime = []
        this.searchReset()
      },
      // 新增/编辑样品单
      addOrEditTo(record) {
          if (record) {
            if (record.createBy != this.userInfo().username) {
              this.$message.error('非当前用户数据不可操作！')
            } else {
              this.$refs.opinion.edit(record)
            }
          } else {
            this.$refs.opinion.add()
          }
      },
      changePicker(value) {
        if (value && value.length > 0) {
            this.queryParam.publishTime_begin = moment(value[0]).format('YYYY-MM-DD HH:mm:ss')
            this.queryParam.publishTime_end = moment(value[1]).format('YYYY-MM-DD HH:mm:ss')
          } else {
            this.queryParam.publishTime_begin = ''
            this.queryParam.publishTime_end = ''
          }
      },
      beginProcess(record) {
        if (record.createBy != this.userInfo().username) {
          return this.$message.error('非当前用户数据不可操作！')
        }

        this.$refs.processConfig.visible = true
        this.$refs.processConfig.formUrl = this.formUrl
        this.$refs.processConfig.formUrlMobile = this.formUrlMobile
        this.$refs.processConfig.flowCode = this.flowCode
        this.$refs.processConfig.edit(record, this.processId, this.beanName)
      },
      // 签发
      signPublish(record) {
        // 判断当前时间是否已经超过截止时间，如果超过截止时间则不能签发
        if (record.blockingTime && moment(record.blockingTime).isBefore(moment())) {
          this.$message.error('意见征集已过期，不支持签发！')
          return
        }
        this.$refs.sign.isProxy = false
        if (record.progress) {
          this.$refs.sign.init(record)
        } else {
          this.$message.info('仅签发人可签发！')
        }
      },
      // 代理签发
      signProxy(record) {
        this.$refs.sign.isProxy = true
        this.$refs.sign.init(record)
      },
      // 查看
      lookTo(record) {
        this.$refs.sign.isProxy = false
        this.$refs.sign.init(record, true)
      }
    }
  }
</script>

<style lang="less" scoped>
  .btn-point{
      font-size: 20px;
  }
  .flex-center{
      display: flex;
      flex-direction: column;
      align-items: center;
  }

</style>
